﻿SSVC.Wrap.Dojo.SetObject("SSVC.MarkupPage", function()
{
	var container = new SSVC.SVG.Container();

	var drawableSettings = [];

	Object.defineProperty(this, "childs",
	{
		get: function() { return container.Childs; },
		set: function(val)
		{
			console.error("MarkupPage.childs property is read only ");
		}
	});

	Object.defineProperty(this, "width",
	{
		get: function() { return container.OX; },
		set: function(val) { container.OX = val; }
	});

	Object.defineProperty(this, "height",
	{
		get: function() { return container.OY; },
		set: function(val) { container.OY = val; }
	});

	Object.defineProperty(this, "clientX",
	{
		get: function() { return container.X; },
		set: function(val) { container.X = val; }
	});

	Object.defineProperty(this, "clientY",
	{
		get: function() { return container.Y; },
		set: function(val) { container.Y = val; }
	});

	Object.defineProperty(this, "position",
	{
		get: function()
		{
			return {
				left: container.Node.style.left.replace("px", ""),
				right: container.Node.style.right.replace("px", ""),
				top: container.Node.style.top.replace("px", ""),
				bottom: container.Node.style.bottom.replace("px", ""),
				width: container.Node.style.width.replace("px", ""),
				height: container.Node.style.height.replace("px", "")
			};
		},
		set: function(val)
		{
			if (val.left)
				container.Node.style.left = val.left;
			if (val.right)
				container.Node.style.right = val.right;
			if (val.top)
				container.Node.style.top = val.top;
			if (val.bottom)
				container.Node.style.bottom = val.bottom;
			if (val.width)
				container.Node.style.width = val.width;
			if (val.height)
				container.Node.style.height = val.height;
		}
	});

	this.placeAt = function(parent)
	{
		parent.appendChild(container.Node);
	};

	this.setSize = function(width, heigth)
	{
		container.OX = width;
		container.OY = heigth;
	};

	this.removeAt = function(parent)
	{
		container.removeChilds();
		try
		{
			parent.removeChild(container.Node);
		}
		catch (e)
		{
			container.Node.parentNode.removeChild(container.Node);
		}
	};

	this.scale = function(factorX, factorY)
	{
		container.Scale(factorX, factorY);
	};

	this.setDrawableSettings = function(settings)
	{
		for (var i in settings)
			drawableSettings[i] = settings[i];
	};

	this.startDrawing = function(elementClass)
	{
		container.StartDrawing(elementClass, drawableSettings);
	};

	this.startEditing = function()
	{
		container.StartMoving();
	};

	this.applyXML = function(xml)
	{
		container.ApplyXml(xml);
	};

	this.getXML = function()
	{
		return container.GetXml();
	};

	this.getInnerXML = function()
	{
		return SSVC.Wrap.Dojo.Xml.innerXML(container.Node);
	};
});
